package com.eightworld3.supermarket.controller;

import com.eightworld3.supermarket.domain.WareInfo;
import com.eightworld3.supermarket.service.WareInfoService;
import com.eightworld3.supermarket.service.dto.WareInfoDTO;
import com.eightworld3.supermarket.service.dto.add.WareInfoAddDTO;
import com.eightworld3.supermarket.service.dto.result.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EightWorld3
 */
@Tag(name = "WareInfoController",description = "商品信息/商品管理")
@RestController
@RequestMapping("/wareInfo")
public class WareInfoController {
    private final WareInfoService wareInfoService;

    /**
     * WareInfoController构造方法
     * @param wareInfoService 商品信息Service
     */
    public WareInfoController(WareInfoService wareInfoService){
        this.wareInfoService = wareInfoService;
    }

    /**
     * 查询所有WareInfo
     * @return 返回所有WareInfo(商品信息)
     */
    @Operation(summary = "查询所有商品信息(WareInfo)",description = "查询所有商品信息(WareInfo)")
    @GetMapping("/allWareInfo")
    public List<WareInfo> getAll(){
        return wareInfoService.selectAll();
    }

    /**
     * 根据WareId查询WareInfo
     * @param wareId ID号
     * @return 返回wareId对应的WareInfo对象(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据WareId查询商品信息(WareInfo)",description = "根据WareId查询商品信息(WareInfo)")
    @GetMapping("/getWareInfoByWareId/{wareId}")
    public ResponseResult getWareInfoByWareId(@PathVariable("wareId")int wareId){
        return wareInfoService.selectByWareId(wareId);
    }

    /**
     * 新增WareInfo
     * @param wareInfoAddDTO WareInfo新增DTO对象
     * @return 返回当前当次新增状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "新增商品信息(WareInfo)",description = "Test：商品类型(外键)、商品名称(varchar(32))、商品等级(varchar(4))、商品总数(>=0)、上下架(0/1)、备注(varchar(120))")
    @PostMapping("/addWareInfo")
    public ResponseResult addWareInfo(@RequestBody WareInfoAddDTO wareInfoAddDTO){
        return wareInfoService.addWareInfo(wareInfoAddDTO);
    }

    /**
     * 更新WareInfo
     * @param wareInfoDTO WareInfo DTO对象
     * @return 返回当前当次更新状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "更新商品信息(WareInfo)",description = "Test：商品类型(外键)、商品名称(varchar(32))、商品等级(varchar(4))、商品总数(>=0)、上下架(0/1)、备注(varchar(120))")
    @PutMapping("/updateWareInfo")
    public ResponseResult updateWareInfo(@RequestBody WareInfoDTO wareInfoDTO){
        return wareInfoService.updateWareInfo(wareInfoDTO);
    }

    /**
     * 根据wareId删除WareInfo
     * @param wareId ID号
     * @return 返回当前当次删除状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据wareId删除商品信息(WareInfo)",description = "根据wareId删除商品信息(WareInfo)")
    @DeleteMapping("/deleteWareInfoByWareId/{wareId}")
    public ResponseResult deleteWareInfoByWareId(@PathVariable("wareId")int wareId){
        return wareInfoService.deleteWareInfoByWareId(wareId);
    }
}
